home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / wstype / source / fswind_n.c < prev    next >
C/C++ Source or Header  |  1991-10-18  |  13KB  |  600 lines

  1. /***   [fswind_n.c]
  2. *
  3. *    ファイルセレクタウィンドウ 関連 (標準)        (C)ささがわ
  4. *
  5. *    For GNU C Compiler (GCC)   Version 1.39
  6. *
  7. ***/
  8.  
  9. #include <string.h>
  10. #include <jctype.h>
  11. #include <dos.h>
  12. #include <direct.h>
  13. #include "window.h"
  14. #include "graph.h"
  15. #include "mos.h"
  16. #include "keyin.h"
  17. #include "fswind.h"
  18. #include "icn.h"
  19. #include "beep.h"
  20. #include "others.h"
  21.  
  22. extern int    PAL_Black;
  23. static struct cvars_t    *cv;
  24. static int    filehd, diroff, ERROR;
  25. static get_f    gf;
  26.  
  27. static void    Draw_window(void);            /* カーソル */
  28. static int    Where(int, int);
  29. static int    Where_drive(int, int);
  30. static int    SUB_drive(int, int);        /* カーソル */
  31. static int    Where_path(int, int);
  32. static int    SUB_path(int, int);            /* カーソル */
  33. static int    Where_file(int, int);
  34. static int    SUB_file(int, int);            /* カーソル */
  35. static void    SUB_scupdw(int);            /* カーソル */
  36. static int    SUB_scupdw_sub(int);
  37. static void    SUB_scdr(int);                /* カーソル */
  38. static void    SUB_move(int, int, struct keyin_t *);    /* カーソル */
  39. static int    Where_kyb(int, int);
  40. static void    SUB_kyb(int, int);            /* カーソル */
  41. static void    allcls(void);                /* カーソル */
  42. static void    errord(void);                /* カーソル */
  43.  
  44. int WIND_file_n(char *path, struct cvars_t *cvars) {
  45.     int        ret = 0, ret2 = 0;
  46.     struct keyin_t    kt;
  47.     
  48.     ICN_mos(0);
  49.     ERROR = 0;
  50.     cv = cvars;
  51.     
  52.     kt.x = cv->wx + 276;
  53.     kt.y = cv->wy + 227 + 20 * cv->drw;
  54.     kt.keta = 14;
  55.     kt.foreC = PAL_Black;
  56.     kt.backC = 7;
  57.     kt.curC = 10;
  58.     kt.buf = path;
  59.     kt.bufn = 80;
  60.     Draw_window();
  61.     Keyin_init(&kt);
  62.     
  63.     ICN_mos(1);
  64.     if (FSW_Draw_path(0, &diroff)) {
  65.         errord();
  66.     } else if (FSW_Draw_diskfree(0)) {
  67.         errord();
  68.     } else {
  69.         filehd = 0;
  70.         if (FSW_Draw_file(0, filehd, &gf))
  71.             return -1;
  72.         FSW_Draw_scrollB(filehd, gf.nfiles);
  73.     }
  74.     ICN_mos(0);
  75.     
  76.     while (!ret && ret2 != 1) {
  77.         char    mb;
  78.         int        wh, mx, my;
  79.         
  80.         if ((ret2 = Keyin()) == -1)
  81.             Keyin_init(&kt);
  82.         
  83.         CLOCK(0);
  84.         if (MOS_rdpos(&mb, &mx, &my), !(mb & 1))
  85.             continue;
  86.         
  87.         if (wh = Where(mx, my), wh == WH_PATH || wh == WH_SCUP || wh == WH_SCDW || wh == WH_SCDR || wh == WH_FILE) {
  88.             if (!ERROR) {
  89.                 switch (wh) {
  90.                     int        sc;
  91.                     
  92.                     case WH_PATH:
  93.                         if (SUB_path(mx, my))
  94.                             ret = -1;
  95.                         break;
  96.                     case WH_SCUP:
  97.                         SUB_scupdw(1);
  98.                         break;
  99.                     case WH_SCDW:
  100.                         SUB_scupdw(0);
  101.                         break;
  102.                     case WH_SCDR:
  103.                         SUB_scdr(my);
  104.                         break;
  105.                     case WH_FILE:
  106.                         if ((sc = SUB_file(mx, my)) == -2) {
  107.                             ret = -1;
  108.                         } else if (sc >= 0) {
  109.                             strlow(1, (gf.pbuf[filehd + sc])->name);
  110.                             strcpy(path, cv->dirbuf);
  111.                             if (strchr(path, '\0')[-1] != '\\')
  112.                                 strcat(path, "\\");
  113.                             strcat(path, (char *)(gf.pbuf[filehd + sc])->name);
  114.                             ret = 1;
  115.                         }
  116.                         break;
  117.                 }
  118.             }
  119.         } else {
  120.             switch (wh) {
  121.                 case WH_END:
  122.                     if (FSW_end())
  123.                         ret = 2;
  124.                     break;
  125.                 case WH_TITLE:
  126.                     SUB_move(mx, my, &kt);
  127.                     break;
  128.                 case WH_OPT1:
  129.                     if (FSW_opt1())
  130.                         ret = 3;
  131.                     break;
  132.                 case WH_OPT2:
  133.                     if (FSW_opt2(&mx, &my)) {
  134.                         cv->sort = my;
  135.                         if (!ERROR) {
  136.                             filehd = 0;
  137.                             FSW_Draw_file(2, filehd, &gf);
  138.                             FSW_Draw_scrollB(filehd, gf.nfiles);
  139.                         }
  140.                     }
  141.                     break;
  142.                 case WH_DRIVE:
  143.                     if (SUB_drive(mx, my))
  144.                         ret = -1;
  145.                     break;
  146.                 case WH_KYB:
  147.                     SUB_kyb(mx, my);
  148.                     break;
  149.                 default:
  150.                     do {
  151.                         MOS_rdpos(&mb, &mx, &my);
  152.                     } while (mb & 1);
  153.                     break;
  154.             }
  155.         }
  156.     }
  157.     
  158.     Gf_bufrel();
  159.     if (ret == -1)
  160.         return -1;
  161.     else if (ret == 2)
  162.         return 0;
  163.     else if (ret == 3)
  164.         return 2;
  165.     else
  166.         return 1;
  167. }
  168.  
  169. static void Draw_window(void) {
  170.     int        a;
  171.     struct opnwin_t    opw;
  172.     static const int    optw[] = {
  173.         2, 2
  174.     };
  175.     
  176.     a = 20 * cv->drw;
  177.     opw.title = cv->title;
  178.     opw.x1 = cv->wx;
  179.     opw.y1 = cv->wy;
  180.     opw.x2 = opw.x1 + 395;
  181.     opw.y2 = opw.y1 + 235 + a;
  182.     opw.canb = 1;
  183.     opw.nopt = 2;
  184.     opw.wopt = optw;
  185.     opw.expb = 0;
  186.     opw.shdw = 1;
  187.     opw.ord = 0;
  188.     MOS_disp(0);
  189.     drawWindow(&opw);
  190.     
  191.     EGB_line(cv->wx + 5, cv->wy + 27 + a, cv->wx + 390, cv->wy + 27 + a, PAL_Black);
  192.     EGB_line(cv->wx + 5, cv->wy + 48 + a, cv->wx + 390, cv->wy + 48 + a, PAL_Black);
  193.     EGB_line(cv->wx + 5, cv->wy + 209 + a, cv->wx + 390, cv->wy + 209 + a, PAL_Black);
  194.     EGB_line(cv->wx + 273, cv->wy + 209 + a, cv->wx + 273, cv->wy + 230 + a, PAL_Black);
  195.     
  196.     DrawScrollbar(0, cv->wx + 374, cv->wy + 48 + a, 162);
  197.     ICN_opt(0, cv->wx + 372, cv->wy + 8);
  198.     EGB_str2("★", cv->wx + 351, cv->wy + 23, PAL_Black);
  199.     FSW_Draw_drive();
  200.     MOS_disp(1);
  201. }
  202.  
  203. static int Where_drive(int x, int y) {
  204.     int        i = 0, xx, yy;
  205.     
  206.     x -= cv->wx;
  207.     y -= cv->wy;
  208.     for (yy = 0; yy < cv->drw; yy++) {
  209.         for (xx = 0; xx < 7; xx++) {
  210.             if (i >= cv->drinfo[0])
  211.                 return -1;
  212.             else if (xx * 53 + 30 < x && x < xx * 53 + 58 && yy * 20 + 29 < y && y < yy * 20 + 44)
  213.                 return i;
  214.             else
  215.                 i++;
  216.         }
  217.     }
  218.     
  219.     return -1;
  220. }
  221.  
  222. static int SUB_drive(int x, int y) {
  223.     int        psc;
  224.     
  225.     if ((psc = Where_drive(x, y)) == -1) {
  226.         char    mb;
  227.         
  228.         do {
  229.             int        mx, my;
  230.             
  231.             MOS_rdpos(&mb, &mx, &my);
  232.         } while (mb & 1);
  233.         return 0;
  234.     }
  235.     
  236.     x = psc % 7;
  237.     y = psc / 7;
  238.     x = cv->wx + x * 53 + 31;
  239.     y = cv->wy + y * 20 + 30;
  240.     if (Button(x, y, x + 26, y + 13)) {
  241.         unsigned    dr;
  242.         
  243.         EGB_rev(1, x, y, x + 26, y + 13);
  244.         ICN_mos(1);
  245.         allcls();
  246.         _dos_setdrive(cv->drinfo[psc * 2 + 1] - 'A' + 1, &dr);
  247.         if (FSW_Draw_path(0, &diroff)) {
  248.             errord();
  249.         } else if (FSW_Draw_diskfree(0)) {
  250.             errord();
  251.         } else {
  252.             ERROR = 0;
  253.             filehd = 0;
  254.             if (FSW_Draw_file(0, filehd, &gf))
  255.                 return -1;
  256.             FSW_Draw_scrollB(filehd, gf.nfiles);
  257.         }
  258.         ICN_mos(0);
  259.     }
  260.     
  261.     return 0;
  262. }
  263.  
  264. static int SUB_path(int mx, int my) {
  265.     int        sc, psc = -1;
  266.     int        xx, yy;
  267.     char    mb;
  268.     
  269.     ICN_mos(2);
  270.     sc = Where_path(mx, my);
  271.     
  272.     xx = cv->wx + 14;
  273.     yy = cv->wy + 30 + 20 * cv->drw;
  274.     do {
  275.         if (sc != -1) {
  276.             if (diroff == 0 && sc <= 2) {
  277.                 sc = 2;
  278.             } else {
  279.                 do {
  280.                     sc++;
  281.                 } while (sc < strlen(cv->dirbuf2) && cv->dirbuf2[sc] != '\\');
  282.                 sc--;
  283.             }
  284.         }
  285.         if (sc == -1 && psc != sc)
  286.             EGB_rev(1, xx, yy, xx + (psc + 1) * 8 - 1, yy + 15);
  287.         else if (sc > psc)
  288.             EGB_rev(1, xx + (psc + 1) * 8, yy, xx + (sc + 1) * 8 - 1, yy + 15);
  289.         else if (sc < psc)
  290.             EGB_rev(1, xx + (sc + 1) * 8, yy, xx + (psc + 1) * 8 - 1, yy + 15);
  291.         psc = sc;
  292.         
  293.         MOS_rdpos(&mb, &mx, &my);
  294.         sc = Where_path(mx, my);
  295.     } while (mb & 1);
  296.     ICN_mos(0);
  297.     
  298.     if (psc != -1) {
  299.         if (diroff != 0)
  300.             cv->dirbuf[diroff + psc - 4] = '\0';
  301.         else
  302.             cv->dirbuf[diroff + psc + 1] = '\0';
  303.         if (strlen(cv->dirbuf) < 3)
  304.             strcpy(cv->dirbuf + 2, "\\");
  305.         ICN_mos(1);
  306.         if (chdir(cv->dirbuf)) {
  307.             errord();
  308.         } else if (FSW_Draw_path(0, &diroff)) {
  309.             errord();
  310.         } else {
  311.             filehd = 0;
  312.             if (FSW_Draw_file(0, filehd, &gf))
  313.                 return -1;
  314.             FSW_Draw_scrollB(filehd, gf.nfiles);
  315.         }
  316.         ICN_mos(0);
  317.     }
  318.     
  319.     return 0;
  320. }
  321.  
  322. static int Where_path(int x, int y) {
  323.     int        sc, ret;
  324.     
  325.     x -= cv->wx;
  326.     y -= cv->wy;
  327.     if (x < 14 || 382 < x || y < 30 + 20 * cv->drw || 45 + 20 * cv->drw < y) {
  328.         ret = -1;
  329.     } else {
  330.         sc = (x - 14) / 8;
  331.         if (strlen(cv->dirbuf2) > sc)
  332.             ret = sc;
  333.         else
  334.             ret = -1;
  335.     }
  336.     
  337.     return ret;
  338. }
  339.  
  340. static void SUB_scupdw(int w) {
  341.     int        mx, my, xx, yy, fllast, flpush = 1;
  342.     char    mb;
  343.     
  344.     if (w) {
  345.         xx = cv->wx + 375;
  346.         yy = cv->wy + 49 + 20 * cv->drw;
  347.     } else {
  348.         xx = cv->wx + 375;
  349.         yy = cv->wy + 194 + 20 * cv->drw;
  350.     }
  351.     
  352.     EGB_rev(1, xx, yy, xx + 14, yy + 14);
  353.     fllast = SUB_scupdw_sub(w);
  354.     TIMER_set(20);
  355.     
  356.     while (MOS_rdpos(&mb, &mx, &my), mb & 1) {
  357.         int        whres;
  358.         
  359.         whres = Where(mx, my) == (w ? WH_SCUP : WH_SCDW);
  360.         if (!whres && flpush || whres && !flpush) {
  361.             EGB_rev(1, xx, yy, xx + 14, yy + 14);
  362.             flpush = !flpush;
  363.         }
  364.         
  365.         if (flpush && TIMER() && !fllast)
  366.             fllast = SUB_scupdw_sub(w);
  367.     }
  368.     
  369.     if (flpush)
  370.         EGB_rev(1, xx, yy, xx + 14, yy + 14);
  371. }
  372.  
  373. static int SUB_scupdw_sub(int w) {
  374.     if (!(w && filehd > 0 || !w && filehd + 8 < gf.nfiles))
  375.         return 1;
  376.     
  377.     w ? filehd-- : filehd++;
  378.     FSW_Draw_scrollB(filehd, gf.nfiles);
  379.     EGB_color(EGB_work, EGB_COL_BACK, 7);
  380.     MOS_disp(0);
  381.     EGB_scrl(1, cv->wx + 14, cv->wy + 49 + 20 * cv->drw, cv->wx + 365, cv->wy + 208 + 20 * cv->drw, 0, w ? 20 : -20);
  382.     FSW_Draw_file_sub(w ? 0 : 7, filehd, &gf);
  383.     MOS_disp(1);
  384.     
  385.     return 0;
  386. }
  387.  
  388. static void SUB_scdr(int my) {
  389.     int        mx, y;
  390.     char    mb;    
  391.     struct sb_t    sb;
  392.     
  393.     ICN_mos(3);
  394.     y = cv->wy + 65 + 20 * cv->drw;
  395.     sb.tl = gf.nfiles;    sb.lpp = 8;
  396.     sb.blen = 128;        sb.bml = 15;
  397.     SCRB_bar(&sb, my - y, &filehd);
  398.     
  399.     FSW_Draw_scrollB(filehd, gf.nfiles);
  400.     FSW_Draw_file(1, filehd, &gf);
  401.     
  402.     while (MOS_rdpos(&mb, &mx, &my), mb & 1) {
  403.         int        a, f;
  404.         
  405.         if (Where(mx, my) != WH_SCDR)
  406.             continue;
  407.         if (SCRB_bar(&sb, my - y, &a), a == filehd)
  408.             continue;
  409.         
  410.         f = a < filehd;
  411.         filehd += f ? -1 : 1;
  412.         FSW_Draw_scrollB(filehd, gf.nfiles);
  413.         EGB_color(EGB_work, EGB_COL_BACK, 7);
  414.         MOS_disp(0);
  415.         EGB_scrl(1, cv->wx + 14, cv->wy + 49 + 20 * cv->drw, cv->wx + 365, cv->wy + 208 + 20 * cv->drw, 0, f ? 20 : -20);
  416.         FSW_Draw_file_sub(f ? 0 : 7, filehd, &gf);
  417.         MOS_disp(1);
  418.     }
  419.     ICN_mos(0);
  420. }
  421.  
  422. static int SUB_file(int mx, int my) {
  423.     int        ret, sc, xx, yy, psc = -1;
  424.     char    mb;
  425.     
  426.     xx = cv->wx + 6;
  427.     yy = cv->wy + 49 + 20 * cv->drw;
  428.     sc = Where_file(mx, my);
  429.     do {
  430.         if (psc != sc) {
  431.             if (psc != -1)
  432.                 EGB_rev(1, xx, yy + psc * 20, xx + 367, yy + (psc + 1) * 20 - 1);
  433.             if (sc != -1)
  434.                 EGB_rev(1, xx, yy + sc * 20, xx + 367, yy + (sc + 1) * 20 - 1);
  435.         }
  436.         psc = sc;
  437.         
  438.         MOS_rdpos(&mb, &mx, &my);
  439.         sc = Where_file(mx, my);
  440.     } while (mb & 1);
  441.     
  442.     if (psc == -1) {
  443.         ret = -1;
  444.     } else if ((gf.pbuf[filehd + sc])->attr & _A_SUBDIR) {
  445.         ICN_mos(1);
  446.         if (chdir((char *)(gf.pbuf[filehd + sc])->name)) {
  447.             errord();
  448.         } else if (FSW_Draw_path(0, &diroff)) {
  449.             errord();
  450.         } else {
  451.             filehd = 0;
  452.             if (FSW_Draw_file(0, filehd, &gf))
  453.                 return -2;
  454.             FSW_Draw_scrollB(filehd, gf.nfiles);
  455.         }
  456.         ICN_mos(0);
  457.         
  458.         ret = -1;
  459.     } else {
  460.         int    i;
  461.         
  462.         for (i = 0; i < 4; i++) {
  463.             for (TIMER_set(5); !TIMER(); );
  464.             EGB_rev(1, xx, yy + psc * 20, xx + 367, yy + (psc + 1) * 20 - 1);
  465.         }
  466.         ret = sc;
  467.     }
  468.     
  469.     return ret;
  470. }
  471.  
  472. static int Where_file(int mx, int my) {
  473.     int        ret;
  474.     
  475.     mx -= cv->wx;
  476.     my -= cv->wy;
  477.     if (mx < 6 || 373 < mx || my < 49 + 20 * cv->drw || 208 + 20 * cv->drw < my) {
  478.         ret = -1;
  479.     } else {
  480.         int        sc;
  481.         
  482.         sc = (my - (49 + 20 * cv->drw)) / 20;
  483.         if (filehd + sc < gf.nfiles)
  484.             ret = sc;
  485.         else
  486.             ret = -1;
  487.     }
  488.     
  489.     return ret;
  490. }
  491.  
  492. static int Where(int x, int y) {
  493.     int        a, i, ret = WH_OTHER;
  494.     static const short    table[12][7] = {
  495.         {5, 26, 5, 26, 0, 0, WH_END},    {26, 348, 5, 26, 0, 0, WH_TITLE},
  496.         {369, 390, 5, 26, 0, 0, WH_OPT1},    {348, 369, 5, 26, 0, 0, WH_OPT2},
  497.         {5, 390, 26, 27, 0, 1, WH_DRIVE},    {5, 390, 27, 48, 1, 1, WH_PATH},
  498.         {5, 374, 48, 209, 1, 1, WH_FILE},    {374, 390, 48, 64, 1, 1, WH_SCUP},
  499.         {374, 390, 64, 193, 1, 1, WH_SCDR},    {374, 390, 193, 209, 1, 1, WH_SCDW},
  500.         {5, 273, 209, 230, 1, 1, WH_FREE},    {273, 390, 209, 230, 1, 1, WH_KYB}
  501.     };
  502.     
  503.     x -= cv->wx;
  504.     y -= cv->wy;
  505.     a = 20 * cv->drw;
  506.     for (i = 0; i < 12; i++) {
  507.         const short    *p;
  508.         
  509.         p = table[i];
  510.         if (p[0] < x && x < p[1] && p[2] + (p[4] ? a : 0) < y && y < p[3] + (p[5] ? a : 0)) {
  511.             ret = p[6];
  512.             break;
  513.         }
  514.     }
  515.     
  516.     return ret;
  517. }
  518.  
  519. static void SUB_move(int x, int y, struct keyin_t *kt) {
  520.     struct RECT    s, w;
  521.     
  522.     w.x1 = cv->wx;    w.y1 = cv->wy;
  523.     w.x2 = cv->wx + 395;    w.y2 = cv->wy + 235 + 20 * cv->drw;
  524.     s.x1 = 0;    s.y1 = 40;    s.x2 = 639;    s.y2 = 463;
  525.     if (dragWindow(x, y, &w, &s, 0, 0)) {
  526.         cv->wx = w.x1;    cv->wy = w.y1;
  527.         MOS_disp(0);
  528.         EGB_cls(0);
  529.         MOS_disp(1);
  530.         kt->x = cv->wx + 276;
  531.         kt->y = cv->wy + 227 + 20 * cv->drw;
  532.         Draw_window();
  533.         Keyin_redisp();
  534.         if (ERROR) {
  535.             errord();
  536.         } else {
  537.             FSW_Draw_diskfree(1);
  538.             FSW_Draw_path(1, &diroff);
  539.             FSW_Draw_file(1, filehd, &gf);
  540.             FSW_Draw_scrollB(filehd, gf.nfiles);
  541.         }
  542.     }
  543. }
  544.  
  545. static void SUB_kyb(int mx, int my) {
  546.     int        sc;
  547.     char    mb;
  548.     
  549.     ICN_mos(2);
  550.     sc = Where_kyb(mx, my);
  551.     do {
  552.         Keyin_cur(sc);
  553.         MOS_rdpos(&mb, &mx, &my);
  554.         sc = Where_kyb(mx, my);
  555.     } while (mb & 1);
  556.     ICN_mos(0);
  557. }
  558.  
  559. static int Where_kyb(int x, int y) {
  560.     int        ret;
  561.     
  562.     x -= cv->wx;
  563.     y -= cv->wy;
  564.     if (x < 276 || 387 < x || y < 212 + 20 * cv->drw || 227 + 20 * cv->drw < y)
  565.         ret = -1;
  566.     else
  567.         ret = (x - 276) / 8;
  568.     
  569.     return ret;
  570. }
  571.  
  572. static void allcls(void) {
  573.     int        a;
  574.     
  575.     a = 20 * cv->drw;
  576.     MOS_disp(0);
  577.     EGB_boxf(cv->wx + 5, cv->wy + 27 + a, cv->wx + 390, cv->wy + 48 + a, PAL_Black, 7);
  578.     EGB_boxf(cv->wx + 5, cv->wy + 48 + a, cv->wx + 374, cv->wy + 209 + a, PAL_Black, 7);
  579.     EGB_boxf(cv->wx + 374, cv->wy + 64 + a, cv->wx + 390, cv->wy + 193 + a, PAL_Black, 6);
  580.     EGB_boxf(cv->wx + 5, cv->wy + 209 + a, cv->wx + 273, cv->wy + 230 + a, PAL_Black, 7);
  581.     MOS_disp(1);
  582. }
  583.  
  584. static void errord(void) {
  585.     int        x, y;
  586.     char    buf[5];
  587.     
  588.     allcls();
  589.     FSW_getdrive(buf);
  590.     MOS_disp(0);
  591.     EGB_str2(buf, cv->wx + 14, cv->wy + 45 + 20 * cv->drw, PAL_Black);
  592.     x = cv->wx + 46;
  593.     y = cv->wy + 48 + 20 * cv->drw;
  594.     EGB_str2("ディスクの有無を確認して", x, y + 70, PAL_Black);
  595.     EGB_str2("  ドライブを選択しなおしてください", x, y + 90, PAL_Black);
  596.     MOS_disp(1);
  597.     BEP_on();
  598.     ERROR = 1;
  599. }
  600.